Repository navigation
fix(solver): resolve extra dependencies missing from a reused package's requires - #10987
Merged
radoering merged 4 commits intoAug 1, 2026
Conversation
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In the fallback path where extra dependencies missing from
requiresare appended, the marker/python constraint filtering applied in the mainrequiresloop is bypassed; consider reusing that filtering logic so that environment-specific markers are still respected for dependencies coming only fromextras. - The
extra_dependency_by_nameandnames_in_requireslookups key solely ondep.name; if there are cases where names are not canonicalized consistently betweenextrasandrequires, consider normalizing (e.g., withcanonicalize_name) in both places to avoid subtle mismatches.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the fallback path where extra dependencies missing from `requires` are appended, the marker/python constraint filtering applied in the main `requires` loop is bypassed; consider reusing that filtering logic so that environment-specific markers are still respected for dependencies coming only from `extras`.
- The `extra_dependency_by_name` and `names_in_requires` lookups key solely on `dep.name`; if there are cases where names are not canonicalized consistently between `extras` and `requires`, consider normalizing (e.g., with `canonicalize_name`) in both places to avoid subtle mismatches.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Sanjays2402
reviewed
Jul 20, 2026
…'s requires Editing pyproject.toml to add an extra to a VCS dependency (eg. changing "sqlalchemy @ git+..." to "sqlalchemy[postgresql] @ git+...") and running `poetry lock` silently drops the extra's own dependencies (eg. psycopg), unless the same change is instead made via `poetry add`. Provider.complete_package() looks up a package's optional/in-extras dependencies by matching names found in `package.extras` against Dependency objects present in `package.requires`. That works for a freshly-inspected package, but a package reused from the lock file (Locker._get_locked_package()) may have a `requires` pruned down to whatever extras were active during an earlier resolution, while `package.extras` always keeps the full mapping. When the matching Dependency object isn't in `requires` anymore, the name is still recognized as needed but nothing gets added to satisfy it. Fall back to the Dependency objects in `package.extras` for names that are entirely absent from `requires`. Names that are present but excluded for another reason (eg. a marker that doesn't match the current environment) are left alone, since that exclusion is deliberate. Fixes python-poetry#10314 Co-authored-by: Claude <noreply@anthropic.com>
…first extra_dependency_by_name used setdefault(), so if an extra listed several same-named dependencies distinguished only by marker (eg. a platform-restricted variant per sys_platform), only the first one seen was kept. If none of them were present in a package's (pruned, reused-from-lock) requires, the fallback added only that first one back, silently dropping the other marker branch. Store a list per name instead and restore all of them. Added a solver-level regression test mirroring test_solver_resolves_duplicate_dependencies_with_restricted_extras, but with both same-named deps only in extras (not requires), which fails on the old setdefault-based fallback.
radoering
force-pushed
the
fix-vcs-extras-not-resolved-from-locked-package-10314
branch
from
August 1, 2026 09:44
d6ab4cb to
5c4994d
Compare
Member
|
@sourcery-ai review |
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/puzzle/test_provider.py" line_range="919-927" />
<code_context>
+ assert {r.name for r in requires} == {"a", "b"}
+
+
+def test_complete_package_respects_marker_exclusion_over_missing_requires(
+ root: ProjectPackage, repository: Repository, pool: RepositoryPool
+) -> None:
+ """
+ A dependency present in `requires` but excluded by a marker mismatch must
+ stay excluded, even though it's also absent from the filtered result (same
+ as a genuinely-missing-from-requires dependency would be).
+ """
+ root = ProjectPackage("root", "1.2.3")
+ root.python_versions = "^3.9"
+ locked_package = Package("A", "1.0", source_type="url", source_url=SOME_URL)
</code_context>
<issue_to_address>
**suggestion:** Avoid shadowing the `root` fixture in `test_complete_package_respects_marker_exclusion_over_missing_requires`
This test reassigns `root = ProjectPackage("root", "1.2.3")`, so the `root` fixture parameter is never used. That hurts readability and consistency with other tests that rely on the shared fixture. Please either remove `root` from the parameters and keep the local instance, or update the fixture itself (e.g., set `python_versions` on the injected `root`).
Suggested implementation:
```python
def test_complete_package_respects_marker_exclusion_over_missing_requires(
root: ProjectPackage, repository: Repository, pool: RepositoryPool
) -> None:
"""
A dependency present in `requires` but excluded by a marker mismatch must
stay excluded, even though it's also absent from the filtered result (same
as a genuinely-missing-from-requires dependency would be).
"""
root.python_versions = "^3.9"
locked_package = Package("A", "1.0", source_type="url", source_url=SOME_URL)
```
The rest of the body of `test_complete_package_respects_marker_exclusion_over_missing_requires` (the `provider = Provider(root, ...)` and subsequent assertions) can stay as-is. This change ensures the injected `root` fixture is used instead of shadowed, while still configuring its `python_versions` for the test.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Member
|
I made the fix more targeted and the test a bit more realistic since this is only an issue of direct origin dependencies. Further, the subsequent filtering is not circumvented anymore. |
radoering
enabled auto-merge (squash)
August 1, 2026 09:55
radoering
approved these changes
Aug 1, 2026
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Check List
Resolves: #10314
What
Editing
pyproject.tomlto add an extra to a VCS dependency (eg. changingsqlalchemy @ git+...tosqlalchemy[postgresql] @ git+...) and runningpoetry locksilently drops the extra's own dependencies (eg.psycopg), unless the same change is instead made viapoetry add.Why
Provider.complete_package()looks up a package's optional/in-extras dependencies by matching names found inpackage.extrasagainstDependencyobjects present inpackage.requires. That works for a freshly-inspected package, but a package reused from the lock file (Locker._get_locked_package()) may have arequireslist pruned down to whatever extras were active during an earlier resolution, whilepackage.extrasalways keeps the full mapping. When the matchingDependencyobject isn't inrequiresanymore, the name is still recognized as needed but nothing gets added to satisfy it.The fix falls back to the
Dependencyobjects inpackage.extrasfor names that are entirely absent fromrequires. Names that are present but excluded for another reason (eg. a marker that doesn't match the current environment) are left alone, since that exclusion is deliberate — a second regression test covers this to make sure the fallback doesn't override legitimate marker-based exclusions.Verification
poetryinstalled from source, using an actual git clone of SQLAlchemy as the VCS dependency.tests/puzzle/test_provider.py.main: an LFS test needing network access, and a Python 3.14/embedded-pip environment issue).ruff check,ruff format --check, andmypyall clean on the changed files.Disclosure: this PR was prepared with the assistance of Claude Code (Anthropic). The investigation, root-cause diagnosis, fix, and verification steps described above were done and checked by me.